<?php
namespace app\wechat\controller;
use think\Config;
use think\Session;
use EasyWeChat\Factory;

class BaseController extends \app\common\controller\BaseController
{
    protected $app;
    protected $apis = ['chooseWXPay',
        'startRecord','stopRecord','playVoice','stopVoice', 'uploadVoice',
        'chooseImage','previewImage','uploadImage'];
    protected $jssdk;
    protected $access_token;

    public function _initialize()
    {
        parent::_initialize();
        if (!$this->checkAuth()) {
            $this->redirect('wechat/Auth/login');
        }
        $this->app = Factory::officialAccount(Config::get('wechat'));
        $this->jssdk = $this->app->jssdk->buildConfig($this->apis);

    }

    /**
     * 验证登录
     * @return bool
     */
    public function checkAuth()
    {
        if (!Session::get('openid') && !Session::get('user_id')&& !Session::get('user_info')) {
            return false;
        } else {
            return true;
        }
    }

}